package com.bitrate.dagger.server.im.config;

import java.util.Collections;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

import lombok.extern.slf4j.Slf4j;

/**
 * 分页插件配置
 */
@Slf4j
@Configuration
public class MyBatisPlusConfig {

	/**
	 * 分页插件 3.5.X
	 */
	@Bean
	public PaginationInnerInterceptor paginationInnerInterceptor() {
		log.debug("注册分页插件");
		PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
		/*
		 * 只负责注册分页插件，不具体设置DbType、方言等 // 设置最大单页限制数量，默认 500 条，-1 不受限制
		 * paginationInnerInterceptor.setMaxLimit(-1L);
		 * paginationInnerInterceptor.setDbType(DbType.TDENGINE); // 开启 count 的 join
		 * 优化,只针对部分 left join paginationInnerInterceptor.setOptimizeJoin(true);
		 */
		return paginationInnerInterceptor;
	}

	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
		mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
		return mybatisPlusInterceptor;
	}

}
